package com.lsy.weizhi2.adapter;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.baidu.mapapi.map.Text;
import com.bumptech.glide.Glide;
import com.lsy.weizhi2.R;
import com.lsy.weizhi2.activity.MySelfMessage2;
import com.lsy.weizhi2.utils.MyMethod;
import com.zhy.autolayout.utils.AutoUtils;

import java.util.List;

/**
 * Created by 嗨哟 on 2017/4/28.
 */

public class MySelfAdapter extends RecyclerView.Adapter {
    private Context context;
    private List<?> list;
    private LayoutInflater layoutInflater;

    public MySelfAdapter(Context context, List<?> list) {
        this.context = context;
        this.list = list;
        layoutInflater=LayoutInflater.from(context);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        View view=layoutInflater.inflate(R.layout.self_item_1,viewGroup,false);
        AutoUtils.autoSize(view);

        return new ItemViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int i) {
        if(viewHolder instanceof ItemViewHolder){
            ((ItemViewHolder) viewHolder).position=i;
            ((ItemViewHolder) viewHolder).name.setText("");
            ((ItemViewHolder) viewHolder).number.setText("");
            Glide.with(context).load("").error(R.mipmap.default_head).into(((ItemViewHolder) viewHolder).head_image);
        }
    }

    @Override
    public int getItemCount() {
        return list==null?0:list.size();
    }

    class ItemViewHolder extends RecyclerView.ViewHolder{
        int position;
        RelativeLayout item_view;
        ImageView head_image;
        TextView name,number;
        public ItemViewHolder(View itemView) {
            super(itemView);
            item_view= (RelativeLayout) itemView.findViewById(R.id.item_view);
            head_image= (ImageView) itemView.findViewById(R.id.head_image);
            name= (TextView) itemView.findViewById(R.id.name);
            number = (TextView) itemView.findViewById(R.id.number);
            item_view.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    MyMethod.toActivity(context,MySelfMessage2.class);
                }
            });
        }
    }

}
